import { Application, utils } from 'pixi.js';
import Selector from './utils/selector.js';

/**
 * 场景
 *
 * Scene
 * 
 * @extends PIXI.Application
 * @class
 * @memberof Nice.DrawBase
 * @author iwangcj
 */
export default class Scene extends Application
{
    /**
     * @param {object} [options] - The optional renderer parameters.
     * @param {boolean} [options.autoStart=true] - Automatically starts the rendering after the construction.
     *     **Note**: Setting this parameter to false does NOT stop the shared ticker even if you set
     *     options.sharedTicker to true in case that it is already started. Stop it by your own.
     * @param {number} [options.width=800] - The width of the renderers view.
     * @param {number} [options.height=600] - The height of the renderers view.
     * @param {HTMLCanvasElement} [options.view] - The canvas to use as a view, optional.
     * @param {boolean} [options.transparent=false] - If the render view is transparent.
     * @param {boolean} [options.autoDensity=false] - Resizes renderer view in CSS pixels to allow for
     *   resolutions other than 1.
     * @param {boolean} [options.antialias=false] - Sets antialias
     * @param {boolean} [options.preserveDrawingBuffer=false] - Enables drawing buffer preservation, enable this if you
     *  need to call toDataUrl on the WebGL context.
     * @param {number} [options.resolution=1] - The resolution / device pixel ratio of the renderer, retina would be 2.
     * @param {boolean} [options.forceCanvas=false] - prevents selection of WebGL renderer, even if such is present, this
     *   option only is available when using **pixi.js-legacy** or **@pixi/canvas-renderer** modules, otherwise
     *   it is ignored.
     * @param {number} [options.backgroundColor=0x000000] - The background color of the rendered area
     *  (shown if not transparent).
     * @param {boolean} [options.clearBeforeRender=true] - This sets if the renderer will clear the canvas or
     *   not before the new render pass.
     * @param {boolean} [options.forceFXAA=false] - Forces FXAA antialiasing to be used over native.
     *  FXAA is faster, but may not always look as great. **(WebGL only)**.
     * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance"
     *  for devices with dual graphics card. **(WebGL only)**.
     * @param {boolean} [options.sharedTicker=false] - `true` to use Nice.Ticker.shared, `false` to create new ticker.
     *  If set to false, you cannot register a handler to occur before anything that runs on the shared ticker.
     *  The system ticker will always run before both the shared ticker and the app ticker.
     * @param {boolean} [options.sharedLoader=false] - `true` to use Nice.Loader.shared, `false` to create new Loader.
     * @param {Window|HTMLElement} [options.resizeTo] - Element to automatically resize stage to.
     */
    constructor(options)
    {
        utils.skipHello();

        super(options);

    }

    /**
     * 
     * @param {*} item 
     */
    addChild(item) {
        item && this.stage && this.stage.addChild(item);
    }

    /**
     * 参考jquery的选择器函数，目前支持 "*"所有元素,"selected"所有选中的元素 ,
     * "#id",某个id元素 ,"[attribute]"包含attribute属性的所有元素,"[attribute=value]" 
     * ,"[attribute!=value]","[attribute$=value]",比如[userData!=],user-data不为空值的元素
     * 参见 http://www.w3school.com.cn/jquery/jquery_ref_selectors.asp
     * @param {string} selector 查询条件
     * @param {number} deep 查找的层次
     */
    select(selector, deep=0) {
        return Selector.select(this.stage, selector, deep);
    }

    /**
     * 查找所有图元
     * @param {number} deep 查找的层次 0所有; 1 一层
     */
    selectAll(deep = 0) {
        return Selector.select(this.stage, "*", deep);
    }


}
